<template>
  <div class="app-container">
    <!--顶部搜索条件-->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="设备名称" prop="deviceName">
        <el-input
          v-model="queryParams.deviceName"
          placeholder="请输入设备名称"
          clearable
          style="width: 240px"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="设备区域" prop="deviceArea">
        <el-select
          v-model="queryParams.deviceArea"
          placeholder="请选择设备区域"
          clearable
          style="width: 240px"
        >
          <el-option
            v-for="dict in dict.type.ygps_device_area"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>


    <!--表格-->
    <el-table v-loading="loading" :data="deviceList" style="width: 100%">
      <el-table-column label="设备名称" prop="deviceName" align="center"/>
      <el-table-column label="设备编号" prop="deviceNo" align="center"/>
      <el-table-column label="设备类型" prop="deviceType" align="center">
        <template slot-scope="scope">
          <span>
            {{
              scope.row.deviceType === 1 ? "温湿度传感器" :
                scope.row.deviceType === 2 ? "gps定位设备" : "错误设备类型"
            }}
          </span>
        </template>
      </el-table-column>
      <el-table-column label="安装区域" prop="deviceArea" align="center">
        <template slot-scope="scope">
          <span>
            {{
              scope.row.deviceArea === "0" ? "常温仓库" :
                scope.row.deviceArea === "1" ? "冷冻库" :
                  scope.row.deviceArea === "2" ? "冷藏库" :
                    scope.row.deviceArea === "4" ? "冷冻车" :
                      scope.row.deviceArea === "5" ? "冷藏车" : "错误安装区域"
            }}
          </span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listReportDevice} from "@/api/iot/device";

export default {
  name: "deviceIndex",
  dicts: ['ygps_device_area'],
  data(){
    return {
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        deviceName: undefined,
        deviceArea: undefined
      },
      showSearch: true,
      deviceList: [],
      loading: false,
      total: 0,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList(){
      this.loading = true
      listReportDevice(this.queryParams).then(response => {
        this.deviceList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    handleQuery(){
      this.queryParams.pageNum = 1
      this.getList()
    },
    resetQuery(){
      this.dateRange = []
      this.resetForm("queryForm")
      this.handleQuery()
    }
  }
}
</script>

<style scoped>

</style>
